@extends('admin.layout.layout')

@section('content')
	
	@if(session('success'))
		<div class="alert alert-success">
			{{session('success')}}
		</div>
	@elseif(session('danger'))
		<div class="alert alert-danger ">
			{{session('danger')}}
		</div>
	@endif
		<div class="danger"></div>
        <div class="panel-body">
        <div class="dataTable_wrapper">
            <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
            <form action="{{url('/admin/goods/list')}}" method="GET">
            <div class="row">
                <div class="col-sm-4">
                <div class="dataTables_length" id="dataTables-example_length">
                    <label>显示 
                        <select name="num" aria-controls="dataTables-example" class="form-control input-sm">
                            <option value="5" @if(!empty($data['num']) && $data['num'] == 5) { selected } @endif>10</option>
                            <option value="10" @if(!empty($data['num']) && $data['num'] == 10) { selected } @endif>20</option>
                            <option value="20" @if(!empty($data['num']) && $data['num'] == 20) { selected } @endif>30</option>
                            <option value="30" @if(!empty($data['num']) && $data['num'] == 30) { selected } @endif>40</option>
                        </select> 条记录
                    </label>
                </div>
                </div>
                <div class="col-sm-4 col-sm-offset-4">
                <div id="dataTables-example_filter" class="dataTables_filter">
                    <label> 商品名:<input type="text" value="{{$data['search'] or ''}}" class="form-control input-sm" name="search" aria-controls="dataTables-example">
                    </label>
                    <button class="btn btn-primary btn-sm">查 询</button>
                </div>
                </div>
            </div>
            </form>
	<div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                
            </div>
            <!-- /.panel-heading -->
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>商品id</th>
                                <th>商品名称</th>
                                <th>商品价格</th>
                                <th>商品库存</th>
                                <th>商品所属分类</th>
                                <th>商品操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($goodsinfo as $v)
                            <tr class="success">
                                <td class="id">{{$v->id}}</td>
                                <td>{{$v->goodsname}}</td>
                                <td>{{$v->price}}</td>
                                <td>{{$v->count}}</td>
                                <td>{{$v->cid}}</td>
                                <td>
                                	<a href="/admin/goods/edit?id={{$v->id}}">编辑</a>
                                	<a href="javascript:void(0)" class="delete">删除</a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                <!-- /.table-responsive -->
            </div>
            <!-- /.panel-body -->
        </div>
    </div>
    <script>

    //绑定单击事件
    $('.delete').click(function(){
    	//获取当前元素的父级
    	var parele = $(this).parents('tr');
    	//获取当前元素的id
    	var id = parele.find('.id').text();
    	//发送ajax请求
		$.ajax({
			url:'/admin/goods/delete',
			data:{'id':id},
			dataType:'json',
			type:'get',
			success:function(data){
    			switch(data){
    				case 0:
    					$('.danger').attr('class','alert alert-success').text('请与管理员联系');
    				case 1:
    					$('.danger').attr('class','alert alert-success').text('商品删除成功');
    					parele.remove();
    			}
    		},
    		error:function(){
    			$('.danger').attr('class','alert alert-danger').text('请与管理员联系');
    		},
    		timeout:1,
    		async:false,
    	});
    })
    </script>

@endsection